﻿using System;
using System.Collections.Generic;
using System.Linq.Expressions;
using System.Reflection;
using System.Text;
using System.Web.Mvc;
using System.Web.Mvc.Html;
using System.Web.Routing;
using RBS.Common;

namespace RBS.Core.Extension
{

    public static class HtmlHelperExtension
    {
        static object GetModelStateValue(HtmlHelper htmlHelper, string key, Type destinationType)
        {
            ModelState modelState;
            if (htmlHelper.ViewData.ModelState.TryGetValue(key, out modelState))
            {
                if (modelState.Value != null)
                {
                    return modelState.Value.ConvertTo(destinationType, null /* culture */);
                }
            }
            return null;
        }
        /// <summary>
        /// 酒店角色
        /// </summary>
        /// <param name="helper"></param>
        /// <param name="hotelRoleIds"></param>
        /// <returns></returns> 
        public static MvcHtmlString HotelRoleHtmlString(this HtmlHelper helper, string hotelRoleIds)
        { 
            var str = new StringBuilder();
// ReSharper disable ReturnValueOfPureMethodIsNotUsed
            hotelRoleIds=hotelRoleIds.Replace("1", "酒店管理员");
            hotelRoleIds = hotelRoleIds.Replace("2", "部长");
            hotelRoleIds = hotelRoleIds.Replace("3", "服务员");
            hotelRoleIds = hotelRoleIds.Replace("4", "收银员");
            hotelRoleIds = hotelRoleIds.Replace("5", "厨师");
            hotelRoleIds = hotelRoleIds.Replace("6", "传菜员");
// ReSharper restore ReturnValueOfPureMethodIsNotUsed
            return new MvcHtmlString(hotelRoleIds);
        }
        /// <summary>
        /// 保证金类型
        /// </summary>
        /// <param name="helper"></param>
        /// <param name="type"></param>
        /// <returns></returns>
        public static MvcHtmlString HtmlRecognizance(this HtmlHelper helper, int type)
        {
            var str = string.Empty;
            // ReSharper disable ReturnValueOfPureMethodIsNotUsed
            switch (type)
            {
                case 1:
                    str = "保证金";
                    break;
                case 2: str = "充值";
                    break;
                case 3: str = "积分";
                    break;
                case 4: str = "消费";
                    break;
                default:
                    str = "保证金";
                    break;
                    
            }
            // ReSharper restore ReturnValueOfPureMethodIsNotUsed
            return new MvcHtmlString(str.ToString());
        }

      /// <summary>
      /// 酒店审核状态
      /// </summary>
      /// <param name="helper"></param>
      /// <param name="auditStatus">审核状态</param>
      /// <returns></returns>
        public static MvcHtmlString HtmlAuditStatus(this HtmlHelper helper, int auditStatus)
        {
            string str; 
            switch (auditStatus)
            {
                case 1:
                    str = "未审核";
                    break;
                case 2: str = "审核未通过";
                    break;
                case 3: str = "审核通过";
                    break;
                case 4: str = "已认证";
                    break;
                default:
                    str = "未审核";
                    break; 
            } 
            return new MvcHtmlString(str);
        }



        /// <summary>
        /// 积分类型
        /// </summary>
        /// <param name="helper"></param>
        /// <param name="type"></param>
        /// <returns></returns>
        public static MvcHtmlString HtmlIntegraType(this HtmlHelper helper, int type)
        {
            string str = null; 
            foreach (int temp in Enum.GetValues(typeof(RBS.Common.RBSEnums.IntegraType)))
            {
                if (temp == type)
                {
                    str = Enum.GetName(typeof(RBS.Common.RBSEnums.IntegraType), temp); 
                    continue; 
                }
            }
            return new MvcHtmlString(str);
        }

        /// <summary>
        /// 订单状态
        /// </summary>
        /// <param name="helper"></param>
        /// <param name="Status"></param>
        /// <returns></returns>
        public static MvcHtmlString HtmlOrderStatus(this HtmlHelper helper, int Status)
        {
            string str = null;   
            Type t = typeof(RBS.Common.RBSEnums.OrderStatus);
            var arrays = Enum.GetValues(t);
            for (int i = 0; i < arrays.LongLength; i++)
            {
               var test = (RBS.Common.RBSEnums.OrderStatus)arrays.GetValue(i);

                if ((int) test != Status) continue;

                FieldInfo fieldInfo = test.GetType().GetField(test.ToString());
                object[] attribArray = fieldInfo.GetCustomAttributes(false);
                var attrib = (EnumDescriptionAttribute)attribArray[0];
                str = attrib.Description;  
            } 
            return new MvcHtmlString(str);
        }

        public static MvcHtmlString HtmlDeedStatus(this HtmlHelper helper, int Status)
        {
            string str = null;
            Type t = typeof(RBS.Common.RBSEnums.DeedStatus);
            var arrays = Enum.GetValues(t);
            for (int i = 0; i < arrays.LongLength; i++)
            {
                var test = (RBS.Common.RBSEnums.DeedStatus)arrays.GetValue(i);

                if ((int)test != Status) continue;

                FieldInfo fieldInfo = test.GetType().GetField(test.ToString());
                object[] attribArray = fieldInfo.GetCustomAttributes(false);
                var attrib = (EnumDescriptionAttribute)attribArray[0];
                str = attrib.Description;
            }
            return new MvcHtmlString(str);
        }


        /// <summary>
        /// 菜单状态
        /// </summary>
        /// <param name="helper"></param> 
        /// <param name="status">菜单状态</param>
        /// <returns></returns>
        public static MvcHtmlString HtmlCookbookStatus(this HtmlHelper helper, int status)
        {
            string str = null;
            foreach (int temp in Enum.GetValues(typeof(RBS.Common.RBSEnums.CookbookStatus)))
            {
                if (temp == status)
                {
                    str = Enum.GetName(typeof(RBS.Common.RBSEnums.CookbookStatus), temp);
                    continue;
                }
            }
            return new MvcHtmlString(str);
        }
    }
}
